<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>图片切换案例</title>
    <style>
      * {
        padding: 0;
        margin: 0;
      }
      html,
      body,
      #mask {
        width: 100%;
        height: 100%;
      }
      #mask {
        background-color: #ccc;
        position: relative;
      }
      #mask .content {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        background-color: white;
        padding: 10px;
      }
      #mask .content > img {
        width: 700px;
        height: 487px;
        display: block;
      }
      #mask .content a {
        text-decoration: none;
        width: 45px;
        height: 100px;
        position: absolute;
        vertical-align: middle;
        top: 180px;
        opacity: 0.5;
      }
      #mask .content a:hover {
        opacity: 0.8;
      }
      #mask .content .left {
        left: 15px;
        text-align: left;
      }
      #mask .content .right {
        right: 15px;
        text-align: right;
      }
    </style>
  </head>
  <body>
    <div id="mask">
      <div class="content">
        <!-- 轮播图 -->
        <img :src="imgArr[index]" class="left" />
        <!-- 左按钮 -->
        <a href="javascript:void(0)" class="left" v-if="index!=0" @click="prev">
          <img src="./img/prev.png" alt="" />
        </a>
        <!-- 右按钮 -->
        <a
          href="javascript:void(0)"
          class="right"
          v-if="index<imgArr.length-1"
          @click="next"
        >
          <img src="./img/next.png" alt="" />
        </a>
      </div>
    </div>
    <!-- 开发环境版本，包含了有帮助的命令行警告 -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>
      var mask = new Vue({
        el: "#mask",
        data: {
          imgArr: [
            "./img/00.jpg",
            "./img/01.jpg",
            "./img/02.jpg",
            "./img/03.jpg",
            "./img/04.jpg",
            "./img/05.jpg",
            "./img/06.jpg",
            "./img/07.jpg",
            "./img/08.jpg",
            "./img/09.jpg",
            "./img/10.jpg",
          ],
          index: 0,
        },
        methods: {
          prev: function () {
            this.index--;
          },
          next: function () {
            this.index++;
          },
        },
      });
    </script>
  </body>
</html>
